/*
 * Copyright 2018 the original author or authors.
 *
 * you can use the file or import project.but Do not take legal responsibility. Only for learning
 * communication.
 *
 * Java compiled version 1.8 or higher
 *
 *
 *
 *
 */

package org.liang.javasource.factory;

import java.util.List;
import org.liang.javasource.bean.BeanInfo;
import org.liang.javasource.config.ClassConfig;
import org.liang.javasource.excel.CreateExampleExcel;


/**
 * 生成javasource源文件的工厂实现类
 * 
 * @author houliang
 * @date 2018年3月5日
 */
public class CreateJavaCodeFactory extends CreateFactory {

  @Override
  public void createJavaCode() {
    ClassConfig config = super.getConfig();
    // 1、生成Bean对象
    List<BeanInfo> beanInfos = CreateExampleExcel.readExcelData(config);
    if (beanInfos == null) {
      return;
    }
    if (beanInfos.size() == 0) {
      System.err.println("可生成文件对象数为0");
      return;
    }
    // 2、生成java文件
    BeanFactory.generateBeans(beanInfos);
  }

  @Override
  public void printJavaCode() {
    ClassConfig config = super.getConfig();
    // 1、生成Bean对象
    List<BeanInfo> beanInfos = CreateExampleExcel.readExcelData(config);
    if (beanInfos == null) {
      return;
    }
    if (beanInfos.size() == 0) {
      System.err.println("可生成文件对象数为0");
      return;
    }
    // 2、生成java文件
    BeanFactory.printBeans(beanInfos);
  }
}
